<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author YDZ
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar> </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ code: record.parent.code })">
          {{ record.parent.code }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup name="ViewsM8RdRd32M8Rd32ListDetails">
  import { unref, onMounted } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { m8Rds32ListData } from '/@/api/m8/rd/rd32/m8Rd32';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';
  import { useQuery } from '/@/hooks/web/usePage';

  const { t } = useI18n('rd.rd32.m8Rd32');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);
  const getQuery = useQuery();

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('发货明细'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('扫一扫'),
        field: 'picBarCode',
        component: 'Input',
      },
      {
        label: t('图名'),
        field: 'picName',
        component: 'Input',
      },
      {
        label: t('出库单号'),
        field: 'parent.code',
        component: 'Input',
      },
      {
        label: t('单据日期'),
        field: 'parent.ddate',
        component: 'RangePicker',
        componentProps: {
          format: 'YYYY-MM-DD',
          showTime: false,
          valueFormat: 'YYYY-MM-DD',
        },
      },
    ],
    fieldMapToTime: [['ddate', ['ddate_gte', 'ddate_lte']]],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('出库单号'),
      dataIndex: 'parent.code',
      key: 'a.code',
      sorter: true,
      width: 130,
      align: 'left',
      slot: 'firstColumn',
    },
    {
      title: t('单据日期'),
      dataIndex: 'parent.ddate',
      key: 'a.ddate',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('图名'),
      dataIndex: 'picName',
      key: 'a.pic_name',
      sorter: true,
      width: 230,
      align: 'left',
    },
    
    {
      title: t('数量'),
      dataIndex: 'iqty',
      key: 'a.iqty',
      sorter: true,
      width: 80,
      align: 'right',
    },
    {
      title: t('备注信息'),
      dataIndex: 'parent.remarks',
      key: 'a.remarks',
      sorter: true,
      width: 230,
      align: 'left',
    },

    {
      title: t('行备注'),
      dataIndex: 'remarks',
      key: 'a.remarks',
      sorter: true,
      width: 230,
      align: 'left',
    },
    {
      title: t('客户'),
      dataIndex: 'parent.basCus.name',
      key: 'a.cus_code',
      sorter: true,
      width: 120,
      align: 'left',
    },
    {
      title: t('制单时间'),
      dataIndex: 'parent.createDate',
      key: 'a.create_date',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('制单人'),
      dataIndex: 'parent.createByName',
      key: 'a.create_by_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    
    {
      title: t('单据状态'),
      dataIndex: 'parent.djStatus',
      key: 'a.dj_status',
      sorter: true,
      width: 100,
      align: 'center',
      dictType: 'dj_status',
      fixed: 'left',
    },
  
  ];

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload, getForm }] = useTable({
    api: m8Rds32ListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    //actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const params = { code: record.code };
    const res = await poOrderDelete(params);
    showMessage(res.message);
    handleSuccess(record);
  }

  onMounted(() => {
    getForm().setFieldsValue({
      'parent.code': getQuery.value.code,
    });
  });

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
